package com.atguigu.jeccache.controller;

import cn.hutool.core.bean.BeanUtil;
import com.atguigu.jeccache.entity.common.result.Result;
import com.atguigu.jeccache.entity.pojo.User;
import com.atguigu.jeccache.entity.vo.UserRespVO;
import com.atguigu.jeccache.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


/**
 * @author Jungle
 * @create 2024-12-21 12:05
 */

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    @GetMapping("/get/{id}")
    public Result<UserRespVO> getUser(@PathVariable Long id) {
        User userById = userService.getUserById(id);
        return Result.success(BeanUtil.toBean(userById, UserRespVO.class));
    }


    @PutMapping("/update")
    public Result<Boolean> updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return Result.success(true);
    }


    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteUser(@PathVariable Long id) {
        userService.deleteUser(id);
        return Result.success(true);
    }

    @GetMapping("/getToken")
    public Result<String> getToken(@RequestParam("type") Integer type) {
        String token = userService.getToken(type);
        return Result.success(token);
    }
}
